package com.hxrfid.web.controller.project;

import cn.dev33.satoken.annotation.SaIgnore;
import com.hxrfid.common.annotation.Log;
import com.hxrfid.common.annotation.RepeatSubmit;
import com.hxrfid.common.core.controller.BaseController;
import com.hxrfid.common.core.domain.PageQuery;
import com.hxrfid.common.core.domain.R;
import com.hxrfid.common.core.page.TableDataInfo;
import com.hxrfid.common.core.validate.AddGroup;
import com.hxrfid.common.core.validate.EditGroup;
import com.hxrfid.common.enums.BusinessType;
import com.hxrfid.common.utils.poi.ExcelUtil;
import com.hxrfid.project.domain.bo.BsBrandBo;
import com.hxrfid.project.domain.vo.BsBrandVo;
import com.hxrfid.project.service.IBsBrandService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 品牌管理
 *
 * @author hxrfid
 * @date 2025-06-12
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/project/brand")
public class BsBrandController extends BaseController {

    private final IBsBrandService iBsBrandService;

    /**
     * 查询品牌管理列表
     */
    @SaIgnore
    @GetMapping("/list")
    public TableDataInfo<BsBrandVo> list(BsBrandBo bo, PageQuery pageQuery) {
        return iBsBrandService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出品牌管理列表
     */
    @Log(title = "品牌管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(BsBrandBo bo, HttpServletResponse response) {
        List<BsBrandVo> list = iBsBrandService.queryList(bo);
        ExcelUtil.exportExcel(list, "品牌管理", BsBrandVo.class, response);
    }

    /**
     * 获取品牌管理详细信息
     *
     * @param id 主键
     */
    @GetMapping("/{id}")
    public R<BsBrandVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iBsBrandService.queryById(id));
    }

    /**
     * 新增品牌管理
     */
    @Log(title = "品牌管理", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody BsBrandBo bo) {
        return toAjax(iBsBrandService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改品牌管理
     */
    @Log(title = "品牌管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody BsBrandBo bo) {
        return toAjax(iBsBrandService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除品牌管理
     *
     * @param ids 主键串
     */
    @Log(title = "品牌管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iBsBrandService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
